﻿@model VM_FinanceRecvPartner
@{
    Layout = "_LayoutMobile";
    ViewBag.Title = "新增收款单";
}
@section header {
    <style>
        .bottombutton {
            padding: 10px;
        }
    </style>
}
<van-nav-bar title="收款单"
             left-arrow
             :fixed="true"
             @@click-left="goBack">
</van-nav-bar>
<van-cell-group>
    <van-cell title="布行名" :value="model.PartnerName||''"></van-cell>
    <van-cell title="收款日期" :value="model.RecvDate||''"></van-cell>
    <van-cell title="应收金额" :value="model.TotalRecvDue"></van-cell>
    <van-cell title="已收金额" :value="model.TotalRecved"></van-cell>
    <van-cell title="未收金额" :value="model.TotalRecvLeft"></van-cell>
    <van-field type="number" v-model="model.Recv"
               label="收款金额"
               placeholder="请输入收款金额"
               :max="model.TotalRecvLeft"
               :label-width="120"
               required></van-field>
    <van-field v-model="model.Remark"
               label="备注"
               placeholder="请输入收款备注"
               maxlength="50"></van-field>
</van-cell-group>
<div class="bottombutton">
    <van-button type="primary" block @@click="onSave">提交</van-button>
</div>
@section footer {
    <script type="text/javascript">
            var modelJson=@(Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model, new Newtonsoft.Json.JsonSerializerSettings()
                  {
                      DateFormatString = "yyyy-MM-dd HH:mm:ss"
                  })))
            var modelData = $.extend(modelJson, {});
        if(modelData.Recv==0){
            modelData.Recv="";
        }
        var pageApp = new Vue({
             el: '#app',
                data: {
                        active:'due',
                        model:modelData,
                },
                    methods: {
                        goBack(){
                            window.location.href = '@(Url.Action("MobileAllList", "FinanceRecvDue"))';
                        },
                        onSave(){
                            const data = this.model;
                            if(!data.PartnerID||data.PartnerID==0)
                            {
                                vant.Toast('布行ID不能为空');
                                return;
                            }
                            if(!data.Recv||data.Recv==0)
                            {
                                vant.Toast('请输入收款金额');
                                return;
                            }
                            if(data.Recv>data.TotalRecvLeft)
                            {
                                vant.Toast('收款金额不能大于应收金额');
                                return;
                            }
                            utils.ajaxPost('@(Url.Action("SavePartnerQuick", "FinanceRecv"))', data, function (resp) {
                                window.location.href = '@(Url.Action("MobileAllList", "FinanceRecvDue"))';
                            }, function (msg) {
                                console.log(msg);
                            });
                        }
                },
            filters: {
                formatDate: function (val) {
                    return utils.formatDate(val, 'yyyy-MM-dd');
                },
            },
        });
        $(function () {
            if(!isMobile())
            {
                    window.location.href = '@(Url.Action("List", "FinanceRecvDue"))/' + modelData.ID + '?nc=' + new Date().getTime();
            }
        });

        function isMobile() {
          const regExp = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
          return regExp.test(navigator.userAgent);
        }
    </script>
}